const app = new Vue({
    el: '#app',
    data() {
        return {
            formData: {},
            oldData: {},
        }
    },
    methods: {
        submitForm() {
            this.$validator.validateAll().then(async (result) => {
                if (result) {
                    //  提交数据
                    var result = await netVpnInfoApi.update(this.formData);
                    if (result.code == 200) {
                        await rxPrompt.msg('修改成功')
                        forward('/network-config/admin_vpn')
                    } else {
                        await rxPrompt.msg('修改失败')
                        return;
                    }
                } else {
                    rxPrompt.msg("输入存在错误")
                }
            });
        },
        restForm() {
            this.formData = _.cloneDeep(this.oldData);
        },
        addType() {
            var setVal = this.formData.ike_ept_type.concat('-', this.formData.ike_hash_type, '-', this.formData.ike_dh_type)
            this.formData.isakmpPolicyValueSet.add(setVal);
            var val = '';
            this.formData.isakmpPolicyValueSet.forEach((obj) => {
                val = val.concat(obj, ',')
            })
            this.formData.isakmpPolicyValue = val;
        },
        addType2() {
            var setVal = this.formData.ike_ept_type1.concat('-', this.formData.ike_hash_type1, '-', this.formData.ike_dh_type1)
            this.formData.ipsecSASecPolicySet.add(setVal);
            var val = '';
            this.formData.ipsecSASecPolicySet.forEach((obj) => {
                val = val.concat(obj, ',')
            })
            this.formData.ipsecSASecPolicy = val;
        },
        cleanType() {
            this.formData.isakmpPolicyValueSet = new Set();
            this.formData.isakmpPolicyValue = '';
        },
        cleanType2() {
            this.formData.ipsecSASecPolicySet = new Set();
            this.formData.ipsecSASecPolicy = '';
        },
        initData(data) {
            data.ike_ept_type = '3des';
            data.ike_hash_type = 'sha1';
            data.ike_dh_type = 'modp768';
            data.ike_ept_type1 = '3des';
            data.ike_hash_type1 = 'sha1';
            data.ike_dh_type1 = 'modp768';
            return data;
        },
    },
    async mounted() {
        const data = this.initData(forward.getData())
        this.formData = _.cloneDeep(data);
        this.oldData = _.cloneDeep(data);
    },

})